

-- Namespace
	local _,mod = ...


-- Constants
	local smfont = {mod.path..'media\\bavaria.ttf',8,'OUTLINEMONOCHROME'}
	local lgfont = {mod.path..'media\\bavaria.ttf',16,'OUTLINEMONOCHROME'}


-- Region creation
	mod.regions['player'] = function()
		local base = mod:CreateFrame('Frame',nil,UIParent)
			base:SetFrameStrata('MEDIUM')
		
		local text = base:CreateFontString(nil,'OVERLAY')
			text:SetFont(unpack(smfont))
			text:SetJustifyH('RIGHT')
			base.text = text
		
		local function fadeout(elapsed)
			local self = base
			local min = self.min
			min = min + elapsed; self.min = min
			if min >= 1 then
				self:Finished()
			elseif min >= .5 then
				self:SetAlpha(1-((min-.5)/.5))
			end
		end
		
		base:Listen('message',function(self,text,crit)
			self.text:SetText(text)
			self.text:SetFont(unpack(crit and lgfont or smfont))
			self.min = 0
			mod:anim_register(fadeout)(0)
		end)
		
		base:Listen('reset',function(self)
			self:SetAlpha(1)
			self.text:SetText('')
			self.min = nil
			mod:anim_unregister(fadeout)
		end)
		
		base:Listen('order',function(self,id)
			self.text:ClearAllPoints()
			self.text:SetPoint('RIGHT',UIParent,'CENTER',-252,random(-116,-42))
		end)
		
		return base
	end


-- Events: damage/healing
	local player = mod:unit('player')
	
	local function CLEU(_,ev,_,src,_,_,_,dest,_,_,_,...)
		if not player(dest) then return end
		
		local amount,crit,_
		local fmt
		
		if ev == 'SPELL_HEAL' or ev == 'SPELL_PERIODIC_HEAL' then
			_,_,_,amount,_,_,crit = ...
			fmt = '|cff7fff7f+|r|cffffffff%d|r'
		elseif ev == 'SPELL_DAMAGE' or ev == 'SPELL_PERIODIC_DAMAGE' or ev == 'RANGE_DAMAGE' then
			_,_,_,amount,_,_,_,_,_,crit = ...
			fmt = '|cffff7f7f-|r|cffffffff%d|r'
		elseif ev == 'SWING_DAMAGE' then
			amount,_,_,_,_,_,crit = ...
			fmt = '|cffff7f7f-|r|cffffffff%d|r'
		else
			return
		end
		
		if amount then
			mod:message('player',
				fmt:format(amount),
				crit
			)
		end
	end
	
	mod:event_register('COMBAT_LOG_EVENT_UNFILTERED',CLEU)

